/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023.
 * Description: set svc's nfs debug info
 * Author: Pang LiYuan
 * Create: 2023-09-15
 */
#include <linux/sunrpc/svc.h>
#include <linux/sunrpc/clnt.h>
#include "rtos_debuginfo.h"

static u64 rpc_srv_throttle = 1;

void nfsd_set_rpc_srv_throttle(u64 throttle)
{
	rpc_srv_throttle = throttle;
}
EXPORT_SYMBOL(nfsd_set_rpc_srv_throttle);

u64 nfsd_get_rpc_srv_throttle(void)
{
	return rpc_srv_throttle;
}
EXPORT_SYMBOL(nfsd_get_rpc_srv_throttle);

void svc_update_debuginfo(const struct svc_procedure *procp, u64 start)
{
	u64 interval = get_jiffies_64() - start;

	if (!procp->pc_debuginfo)
		return;

	if (interval >= rpc_srv_throttle)
		procp->pc_debuginfo->pc_cnt++;
	if (interval > procp->pc_debuginfo->pc_max_time)
		procp->pc_debuginfo->pc_max_time = interval;
	procp->pc_debuginfo->pc_time_total += interval;
}
